package com.eleventwelve.iris.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.opentides.bean.FileInfo;
import org.opentides.service.FileInfoService;
import org.opentides.util.StringUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class ScannedFilePreviewController extends AbstractController{
	private String viewName;
	private FileInfoService fileInfoService;
	
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String fileId = request.getParameter("id");
		FileInfo fileInfo = null;
		
		if(!StringUtil.isEmpty(fileId) && StringUtils.isNumeric(fileId)){
			fileInfo = fileInfoService.load(fileId);
			
		}
		
		return new ModelAndView(viewName, "file", fileInfo);
		
	}


	public String getViewName() {
		return viewName;
	}


	public void setViewName(String viewName) {
		this.viewName = viewName;
	}


	public FileInfoService getFileInfoService() {
		return fileInfoService;
	}


	public void setFileInfoService(FileInfoService fileInfoService) {
		this.fileInfoService = fileInfoService;
	}

}
